﻿package mortal.game.view.rebate.openServerSevenDay.panel
{
    import com.gengine.core.frame.*;
    import com.mui.controls.*;
    import extend.language.*;
    import mortal.common.global.*;
    import mortal.game.cache.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.rebate.openServerSevenDay.data.*;

    public class OpenServerSevenDayTop extends GSprite
    {
        protected var _bg:GImageBitmap;
        protected var _day:BitmapNumberText;
        protected var _hour:BitmapNumberText;
        protected var _min:BitmapNumberText;
        protected var _titleDes:GBitmap;
        protected var _activeTime:GTextFiled;
        protected var _actRule:GTextFiled;
        protected var _dayNum:BitmapNumberText;
        protected var _notOpenTip:GBitmap;
        private var _secT:SecTimer;
        private var _timeTab:int = -1;
        private static var _dayName:Array = Language.getArrayByStr(71886);

        public function OpenServerSevenDayTop()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._bg = UIFactory.gImageBitmap(ImagesConst.OpenServerSevenDayBgCom, 0, 0, this);
            this._day = UIFactory.bitmapNumberText(159, 152, "QuestionCopyNum.png", 18, 25, -2, this, 13, 1);
            this._day.text = "2";
            this._hour = UIFactory.bitmapNumberText(211, 152, "QuestionCopyNum.png", 18, 25, -2, this, 13, 1);
            this._hour.text = "12";
            this._min = UIFactory.bitmapNumberText(283, 151, "QuestionCopyNum.png", 18, 25, -2, this, 13, 1);
            this._min.text = "59";
            this._titleDes = UIFactory.gBitmap(ImagesConst.OpenServerSevenDayTitle1, 62, 53, this);
            this._activeTime = UIFactory.gTextField("" + Language.getString(71887), 15, 179, 430, 20, this, GlobalStyle.textFormatPutong.setColor(16777215));
            this._actRule = UIFactory.gTextField("" + Language.getString(71888), 14, 197, 500, 20, this, GlobalStyle.textFormatPutong.setColor(16777215));
            this._actRule.multiline = true;
            this._actRule.wordWrap = true;
            this._dayNum = UIFactory.bitmapNumberText(148, 6, "WizardCombatNum.png", 23, 30, -3, this, 13, 1);
            this._dayNum.text = "1";
            this._notOpenTip = UIFactory.gBitmap(ImagesConst.OpenServerSevenTimeTip, 0, 150, this);
            this._notOpenTip.visible = false;
            this._secT = new SecTimer(1);
            this._secT.addListener(TimerType.ENTERFRAME, this.timeCk);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._bg = null;
            this._day = null;
            this._hour = null;
            this._min = null;
            this._titleDes = null;
            this._activeTime = null;
            this._actRule = null;
            this._dayNum = null;
            this._notOpenTip = null;
            this._secT.dispose();
            this._secT = null;
            this._timeTab = -1;
            return;
        }// end function

        public function updateTimeByIndex(param1:int) : void
        {
            this.updateBg(param1);
            this.updateDayTitle(param1);
            this.updateTime(param1);
            this.updateRule(param1);
            return;
        }// end function

        private function updateBg(param1:int) : void
        {
            if (this._bg)
            {
                this._bg.dispose();
                this._bg = null;
            }
            if (param1 == 0)
            {
                this._bg = UIFactory.gImageBitmap(ImagesConst.OpenServerSevenDayBgPower, 0, 0, this);
            }
            else if (param1 == 1)
            {
                this._bg = UIFactory.gImageBitmap(ImagesConst.OpenServerSevenDayBgLevel, 0, 0, this);
            }
            else
            {
                this._bg = UIFactory.gImageBitmap(ImagesConst.OpenServerSevenDayBgCom, 0, 0, this);
            }
            this.addChildAt(this._bg, 0);
            return;
        }// end function

        private function updateDayTitle(param1:int) : void
        {
            var _loc_2:* = Cache.instance.openServerSevenDay.sevenDayTabArr[param1];
            if (_loc_2 == null)
            {
                return;
            }
            if (_loc_2.dayNum == OpenServerSevenDayUtil.PowNum || _loc_2.dayNum == OpenServerSevenDayUtil.LevelNum)
            {
                this._dayNum.visible = false;
            }
            else
            {
                this._dayNum.visible = true;
                this._dayNum.text = "" + _loc_2.dayNum;
            }
            if (param1 == 0 || param1 == 1)
            {
                this._titleDes.visible = false;
            }
            else
            {
                this._titleDes.visible = true;
                this._titleDes.dispose();
                this._titleDes = UIFactory.gBitmap(ImagesConst["OpenServerSevenDayTitle" + _loc_2.dayNum], 62, 53, this);
            }
            return;
        }// end function

        private function updateTime(param1:int) : void
        {
            this._timeTab = param1;
            var _loc_2:* = Cache.instance.openServerSevenDay.sevenDayTabArr[this._timeTab];
            if (_loc_2 == null)
            {
                return;
            }
            var _loc_3:* = OpenServerSevenDayUtil.getCountDownTime(_loc_2.dayNum);
            if (this._timeTab == 0 || this._timeTab == 1)
            {
                this._notOpenTip.visible = false;
                this.timeCk(null);
            }
            else if (OpenServerSevenDayUtil.isTodayByTabIndex(this._timeTab) == 0)
            {
                this._notOpenTip.visible = false;
                this.timeCk(null);
            }
            else
            {
                this._notOpenTip.visible = true;
            }
            return;
        }// end function

        private function timeCk(param1:SecTimer) : void
        {
            var _loc_3:Array = null;
            var _loc_4:int = 0;
            if (this._timeTab == -1)
            {
                this._secT.stop();
                return;
            }
            var _loc_2:* = Cache.instance.openServerSevenDay.sevenDayTabArr[this._timeTab];
            if (_loc_2 == null)
            {
                return;
            }
            if (this._timeTab == 0 || this._timeTab == 1)
            {
                _loc_3 = OpenServerSevenDayUtil.get7dayCountDownTime();
            }
            else
            {
                _loc_3 = OpenServerSevenDayUtil.getCountDownTime(_loc_2.dayNum);
            }
            _loc_4 = _loc_3[3];
            this._day.text = "" + _loc_3[0];
            this._hour.text = "" + _loc_3[1];
            this._min.text = "" + _loc_3[2];
            if (_loc_4 > 0 && this._secT.running == false)
            {
                this._secT.start();
            }
            else
            {
                this._secT.stop();
            }
            return;
        }// end function

        private function updateRule(param1:int) : void
        {
            var _loc_2:* = Cache.instance.openServerSevenDay.sevenDayTabArr[param1];
            if (_loc_2 == null)
            {
                return;
            }
            var _loc_3:int = 0;
            var _loc_4:int = 1;
            if (param1 == 0 || param1 == 1)
            {
                _loc_3 = 1;
                _loc_4 = 7;
            }
            else
            {
                _loc_3 = _loc_2.dayNum;
                _loc_4 = 1;
            }
            var _loc_5:* = "" + OpenServerSevenDayUtil.getFullDayString(_loc_3);
            _loc_5 = _loc_5 + ("-" + OpenServerSevenDayUtil.getFullDayString(_loc_3 + _loc_4));
            this._activeTime.text = Language.getString(71887) + _loc_5;
            this._actRule.text = Language.getString(71888) + Cache.instance.openServerSevenDay.ruleStrObj[_loc_2.dayNum];
            return;
        }// end function

    }
}
